/*
 * @Description: 
 * @Author: mmzhang
 * @Date: 2021-12-10 16:52:09
 * @LastEditTime: 2022-11-22 14:26:04
 */
import Opt from '@/components/dt/info/Opt.js'
import dateOpt from '@/biz/option/date.js'
import ruleOpt from '@/biz/option/rule.js'
import tool from '@/common/tool.js'

let _this = null

let curYear = new Date().getFullYear()
let curMonth = new Date().getMonth() + 1
let yearArr = [
{
  key: curYear,
  value: curYear + '年'
}, {
  key: curYear - 1,
  value: curYear - 1 + '年'
}]

let initMonthArr = [
{
  key: '0',
  value: '全部'
}]
for (let i = 1; i <= curMonth; i++) {
  let obj = {
    key: i + '',
    value: i + '月'
  }
  initMonthArr.push(obj)
}

let monthObj = {
  key: 'month',
  select: {
    options: initMonthArr
  },
}
class SearchOpt extends Opt {

  constructor(vm) {
    _this = vm
    super()
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [
    {
      key: 'year',
      select: {
        options: yearArr
      },
      change: (val) => {
        let monthArr = [{
          key: '0',
          value: '全部'
        }]
        if (val.value == curYear) {
          for (let i = 1; i <= curMonth; i++) {
            let obj = {
              key: i + '',
              value: i + '月'
            }
            monthArr.push(obj)
          }
          monthObj.select.options = monthArr
        } else {
          for (let i = 1; i <= 12; i++) {
            let obj = {
              key: i + '',
              value: i + '月'
            }
            monthArr.push(obj)
          }
          monthObj.select.options = monthArr
        }
      }
    }, monthObj]
  }
}

export default SearchOpt